<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ page import = "com.shopping.user.*" %>
<%@ page import = "com.shopping.service.*" %>
<%@ page import = "com.shopping.exception.*" %>
<!DOCTYPE html PUBLIC>

<%
	request.setCharacterEncoding("utf-8");
	String action = request.getParameter("action");
	if(action != null && action.equals("login")) {
		String username = request.getParameter("user");
		String password = request.getParameter("password");
		User u = null;
		
		try{
			u = UserService.login(username,password);
		}catch(UsernameNotFoundException e) {
			out.println("用户不存在");
			return;
		}catch(PasswordNotCorrectionException e) {
			out.println("密码不正确");
			return;
		}
		session.setAttribute("user",u);
		
		response.sendRedirect("service_self.jsp");
	}
	
 
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
  <form action="userlogin.jsp" name="form" method="post">
    <input type="hidden" name="action" value="login">
    <table>
      <tr>
        <td>用户名:
          <input type="text" name="user" size="30">
        </td>
      </tr>
       <tr>
        <td>密码:&nbsp;&nbsp;&nbsp;&nbsp;
          <input type="password" name="password" size="30">
        </td>
      </tr>
       <tr>
        <td>
          <input type="submit" name="submit" value="登录"> 
          <br>
          <a href="register.jsp">注册新用户</a>
        </td>
      </tr>
    </table>
  </form>
</body>
</html>